<template>
  <div class="my-continer">
    <div class="list">
      <Card
        class="card"
        header
        v-for="(item, index) of list"
        :key="index"
        @click="onJump({ path: '/detail', query: { id: item.id } })"
      >
        <template #header>
          <div class="top">
            <div class="customer-code">
              <div class="code">客户号码: {{ item.customerPhone }}</div>
            </div>
            <Status :type="item.transferState ? 'complete' : 'not-complete'">{{
              item.overState ? "已结单" : "未结单"
            }}</Status>
          </div>
          <div class="bottom">
            <IconStatus
              :type="item.transferState ? 'complete' : 'not-complete'"
              >{{ item.transferState ? "已转派" : "未转派" }}</IconStatus
            >
          </div>
        </template>

        <!-- 主体部分 -->
        <div class="content">
          <div class="field">
            <span class="name">工单时间</span>
            <span class="value">{{ item.createTime }}</span>
          </div>
          <div class="field">
            <span class="name">单元区域</span>
            <span class="value">{{ item.unit }}</span>
          </div>
          <div class="field">
            <span class="name">客户标识</span>
            <span class="value">{{ item.customerTag }}</span>
          </div>
          <div class="field">
            <span class="name">集团类别</span>
            <span class="value">{{ item.groupType }}</span>
          </div>
          <div class="field">
            <span class="name">集团名称</span>
            <span class="value">{{ item.groupName }}</span>
          </div>
        </div>
      </Card>
    </div>
  </div>
</template>

<script setup>
import { omsmFind } from "@/api/index";

import { showLoadingToast, closeToast } from "@/utils/toast.js";

import { ref, onMounted } from "vue";

import { useRouter } from "vue-router";
const router = useRouter();

const onJump = (data = {}) => {
  router.push(data);
};

const list = ref([]);

onMounted(() => {
  fetchData();
});

// 把  方法“抛”出去
defineExpose({
  fetchData,
});

async function fetchData(data = {}) {
  showLoadingToast();
  list.value = (await omsmFind(data))?.result || [];
  closeToast();
}
</script>

<style lang="scss" scoped>
.list {
  display: flex;
  flex-direction: column;
  align-items: center;

  .card {
    margin-bottom: 16px;

    .top {
      display: flex;
      justify-content: space-between;

      .customer-code {
        display: flex;
        align-items: center;
        font-size: 15px;
        font-weight: 600;
      }
    }

    .content {
      .field {
        margin-top: 4px;
        display: flex;
        align-items: center;
        font-size: 13px;

        .name {
          font-weight: 400;
        }

        .value {
          margin-left: 10px;
          color: #888;
        }

        &:first-child {
          margin-top: 0;
        }
      }
    }
  }
}
</style>